package com.example.propertymangesystem.controller;

import com.example.propertymangesystem.controller.util.R;
import com.example.propertymangesystem.domain.employee;
import com.example.propertymangesystem.domain.property;
import com.example.propertymangesystem.service.IPropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/properties")
public class propertyController {

    @Autowired
    private IPropertyService propertyService;


    //获取全部
    @GetMapping
    public R getAll() {
        return new R(true, propertyService.list(null));
    }

    //分页查询
    @GetMapping("/{current}/{size}")
    public R getPage(@PathVariable Integer current, @PathVariable Integer size, property property){
        return new R(true, propertyService.getPage(current, size, property));
    }

    //根据id查询
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id){
        property property  = propertyService.getById(id);
        boolean b = false;
        if(property != null) b = true;
        return new R(b,  property);
    }

    //修改数据
    @PutMapping
    public R update(@RequestBody property property){
        boolean b = propertyService.updateById(property);
        return new R(b, b ? "修改成功^_^":"修改失败^…^");
    }

    //添加
    @PostMapping
    public R save(@RequestBody property property){
        boolean b = propertyService.save(property);
        return new R(b, b ? "添加成功^_^":"添加失败^…^");
    }

    //删除
    @DeleteMapping("/{id}")
    public R delete(@PathVariable Integer id){
        boolean b = propertyService.removeById(id);
        return new R(b, b ? "删除成功^_^":"删除失败^…^");
    }
}
